package AnsatzTilo;

public class Clock implements Runnable{
	
	private long systemTime = 0;
	private long terminationTime;
	private long sleep;
	private boolean termination;
	private Thread ClockThread;

	public Clock(long sleep, long terminationTime) {
		this.sleep = sleep;
		this.terminationTime = terminationTime;
		this.termination = false;
	}
	
	public void run() {
		while(true){
			this.termination = systemTime >= terminationTime; 
			systemTime++;
			tick();
			//System.out.println("Aktuelle Zeit: " + systemTime);
		}
	}
	
	public void tick(){
		try {
			Thread.sleep(this.sleep);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void start(){
		ClockThread = new Thread(this);
		ClockThread.start();
	}
	
	public void stop(){
		ClockThread.interrupt();
	}
	
	public boolean isTerminated(){
		return this.termination;
	}
		
	public long getSystemTime(){
		return this.systemTime;
	}
			
}
